<template>
  <div>
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="4" :lg="4">
          <p>状态</p>
          <el-select v-model="IsEnabled" size="mini" @change="getStafflist()">
            <el-option label="全部" value="" />
            <el-option label="启用" :value="true" />
            <el-option label="停用" :value="false" />
          </el-select>
        </el-col>
        <el-col :md="4" :lg="4">
          <p>姓名/手机号</p>
          <el-input v-model="Api_GET_ClubEmployeeQO.Filter" placeholder="请输入姓名/手机号" size="mini" clearable @change="getStafflist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="check">筛选</el-button>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-button type="primary" style="margin-top:15px" size="mini" icon="el-icon-circle-plus-outline" @click="add">添加员工</el-button>
    </div>
    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column type="index" label="序号" align="center" width="100" />
        <el-table-column label="手机号" prop="phoneNumber" />
        <el-table-column label="姓名" prop="name" />
        <el-table-column label="角色" prop="roleName" />
        <el-table-column label="标签">
          <template slot-scope="{ row }">
            <span v-for="(item,index) in row.employeeEmployeeTags" :key="index">
              {{ item.employeeTagName }} {{ row.employeeEmployeeTags.length > 0 ? row.employeeEmployeeTags.length - 1 === index ? '': '/' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="添加时间">
          <template slot-scope="{ row }">
            <span>
              {{ row.creationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="{row}">
            <div v-if="row.isEnabled === true"><i class="success_circle" />已启用</div>
            <div v-else><i class="error_circle" />已停用</div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button v-if="row.isEnabled === true" type="text" size="mini" style="color:red" @click="stop(row.id)">停用</el-button>
            <el-button v-if="row.isEnabled === false" type="text" size="mini" @click="start(row.id)">启用</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="editE(row.id)">编辑</el-button>
            <el-button type="text" size="mini" style="color:#FF3434" @click="deleteE(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <add-staff ref="addStaff" @flag="go" /> -->
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubEmployeeQO.Page"
        :page-size="Api_GET_ClubEmployeeQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { api_GET_ClubEmployee, api_DELETE_ClubEmployeeId, api_POST_ClubEmployeeIdDisable, api_POST_ClubEmployeeIdEnable } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubEmployeeQO, Api_GET_ClubEmployeeTagQO } from '@/lib/form/hall/swaggerForm';
import { Api_GET_RolesQO } from '@/lib/form/swaggerForm';
import { mapState, mapActions } from 'vuex';
export default {
  components: {
    // addStaff,
    // EditStaff
  },
  data() {
    return {
      tableLoading: false,
      currentPage: 1,
      totalPage: 0,
      IsEnabled: '',
      EmployeeTag: {},
      Api_GET_ClubEmployeeTagQO: new Api_GET_ClubEmployeeTagQO(), // 标签列表
      Api_GET_RolesQO: new Api_GET_RolesQO(),
      roles: {},
      Api_GET_ClubEmployeeQO: new Api_GET_ClubEmployeeQO(),
      flag: true,
      tableData: [
        {

        }
      ]
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.getStafflist();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    add() {
      this.$router.push({ 'name': 'Editstaff' });
    },
    getStafflist(page) {
      this.tableLoading = true;
      this.Api_GET_ClubEmployeeQO.OrganizationUnitId = this.user;
      this.Api_GET_ClubEmployeeQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubEmployeeQO.Page = page || 1;
      this.Api_GET_ClubEmployeeQO.SkipCount = (this.Api_GET_ClubEmployeeQO.Page - 1) * this.Api_GET_ClubEmployeeQO.MaxResultCount;
      this.Api_GET_ClubEmployeeQO.IsEnabled = this.IsEnabled;
      this.Api_GET_ClubEmployeeQO.IncludeIdCardType = null;
      this.Api_GET_ClubEmployeeQO.CanTeach = null;
      this.Api_GET_ClubEmployeeQO.IncludeEmployeeEmployeeTags = true;
      console.log(this.Api_GET_ClubEmployeeQO);
      api_GET_ClubEmployee(this.Api_GET_ClubEmployeeQO).then(res => {
        console.log(res);
        this.totalPage = res.totalCount;
        this.tableData = res.items;
        this.tableLoading = false;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 删除员工
    deleteE(id) {
      this.$confirm(`您确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_DELETE_ClubEmployeeId(id).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getStafflist(this.Api_GET_ClubEmployeeQO.Page);
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    editE(id) {
      this.flag = false;
      this.$router.push({ 'name': 'Editstaff', query: { 'id': id }});
    },
    check() {
      this.getStafflist();
    },
    // 停用
    stop(id) {
      this.$confirm(`您确定要停用吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_POST_ClubEmployeeIdDisable(id).then(res => {
            this.$message({
              message: '停用成功',
              type: 'success'
            });
            this.getStafflist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    start(id) {
      this.$confirm(`您确定要启用吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_POST_ClubEmployeeIdEnable(id).then(res => {
            this.$message({
              message: '启用成功',
              type: 'success'
            });
            this.getStafflist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubEmployeeQO.MaxResultCount = MaxResultCount;
      this.getStafflist();
    },
    pageIndexChange(currentPage) {
      this.getStafflist(currentPage);
    }
  }

};
</script>

<style lang="scss" scoped>
.success_circle {
  display: inline-block;
  margin-right: 8px;
  width: 6px;
  height: 6px;
  background: #14CE67;
  border-radius: 50%;
}
.error_circle {
  display: inline-block;
  margin-right: 8px;
  width: 6px;
  height: 6px;
  background: #FF3434;
  border-radius: 50%;
}
</style>
